//
//  ViewController.m
//  guicalc
//
//  Created by iD Student on 6/25/13.
//  Copyright (c) 2013 iD Student. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController
long double first = 0.0;
int op = 0;
long double second = 0.0;

char* operation = "";
int oper = 0;

int control = 0;

double equal = 0;

-(IBAction)getNumber:(id)sender{
    number = (long)[sender tag];
    if(control == 0){
        first = (first * 10)+ number;
    }else if(control == 1){
        second = (second * 10) + number;
    }else{
        
    }
    
    if(second > 0){
        [Answer setText:[NSString stringWithFormat:@"%.0Lf %s %.0Lf", first, operation, second]];
    }else{
        [Answer setText:[NSString stringWithFormat:@"%.0Lf %s", first, operation]];
    }
}
-(IBAction)clear:(id)sender{
    first = 0;
    second = 0;
    oper = 0;
    control = 0;
    if(second > 0){
        [Answer setText:[NSString stringWithFormat:@"%.0Lf %s %.0Lf", first, operation, second]];
    }else{
        [Answer setText:[NSString stringWithFormat:@"%.5Lf %s", first, operation]];
    }
}
-(IBAction)getop:(id)sender{
    oper = [sender tag];
    if(oper == 1){
        operation = "/";
    }else if(oper == 2){
        operation = "*";
    }else if(oper == 3){
        operation = "-";
    }else if(oper == 4){
        operation = "+";
    }else{
        operation = "";
    }
    control = 1;
    if(second > 0){
        [Answer setText:[NSString stringWithFormat:@"%.0Lf %s %.0Lf", first, operation, second]];
    }else{
        [Answer setText:[NSString stringWithFormat:@"%.5Lf %s", first, operation]];
    }
    
}
-(IBAction)equals:(id)sender{
    if(oper == 1){
        first = first/second;
    }else if(oper == 2){
        first = first * second;
    }else if(oper == 3){
        first = first - second;
    }else if(oper == 4){
        first = first + second;
    }else{
        operation = "";
    }
    oper = 0;
    control = 1;
    second = 0;
    if(oper == 1){
        operation = "/";
    }else if(oper == 2){
        operation = "*";
    }else if(oper == 3){
        operation = "-";
    }else if(oper == 4){
        operation = "+";
    }else{
        operation = "";
    }
    if(second > 0){
        [Answer setText:[NSString stringWithFormat:@"%.0Lf %s %.0Lf", first, operation, second]];
    }else{
        [Answer setText:[NSString stringWithFormat:@"%.5Lf %s", first, operation]];
    }
    
}


- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
